%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tutorial for solving the time-dependent Schr?dinger equation in MATLAB.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;

Omega = 1;
Delta = 0;

time = [0:.01:1]*10;

psi0 = [1 ; 0];

for k=1:length(time)
    t = time(k);
    H = [ 0     Omega
          Omega Delta ];

    psi  = expm(1i*H*t)*psi0;
    
    a1(k) = abs(psi(1))^2;
    a2(k) = abs(psi(2))^2;
end

figure(1);          clf;
plot(time,a2)